package com.example.function.integration.mapper;

import com.example.function.integration.entity.HuanengCreditDataEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;

public interface CrlCreditApplyRecordExtendMapper {

    @Insert("insert into crl_credit_apply_record (" +
            "company_id,tenant_id,credit_apply_no,credit_apply_type,product_code,product_version,channel_code,customer_code,user_id,outside_credit_no,bdc_channel_code,out_channel_code,outside_req_time,channel_customer_code,credit_apply_status,req_time,finished_time,biz_date,tag1,tag2,user_name,cert_no,apply_msg,credit_batch_no) values " +
            "(#{companyId},#{tenantId},#{creditApplyNo},#{creditApplyType},#{productCode},#{productVersion},#{channelCode},#{customerCode},#{userId},#{outsideCreditNo},#{bdcChannelCode},#{outChannelCode},#{outsideReqTime},#{channelCustomerCode},#{creditApplyStatus},#{reqTime},#{finishedTime},#{bizDate},#{tag1},#{tag2},#{userName},#{certNo},#{applyMsg},#{creditBatchNo})")
    int insert(T creditApplyRecord);

    @Select("select " +
            "cr.id as serialNumber, " +
            "cr.credit_apply_no as creditApplyNo, " +
            "cr.outside_credit_no as outsideCreditNo, " +
            "cr.customer_code as customerCode, " +
            "cr.user_name as customerName, " +
            "cr.cert_no as customerCertNo," +
            "cr.req_time as applyTime, " +
            "cr.product_code as productCode," +
            "br.credit_quota as creditQuota, " +
            "br.normal_year_rate as fixedPrice, " +
            "cr.credit_apply_status as creditApplyStatus," +
            "ar.approve_req_content as approveReqContent, " +
            "ar.approve_ret_content as approveRetContent " +
            "from crl_credit_apply_record cr " +
            "left join crl_credit_contract_record br on cr.credit_apply_no = br.credit_apply_no " +
            "left join crl_credit_approve_record ar on br.credit_apply_no = ar.credit_apply_no  " +
            "where cr.tenant_id = #{tenantId,jdbcType=VARCHAR} " +
            "and cr.id > #{startId,jdbcType=BIGINT} " +
            "order by cr.id limit #{limit,jdbcType=INTEGER}")
    List<HuanengCreditDataEntity> selectCreditApplyData(@Param("tenantId") String tenantId,
                                                        @Param("startId") Long startId,
                                                        @Param("limit") Long limit);

}
